package com.training.java.core.equals;


	/**
	 * The purpose of this class is to observe how the equals compare 2 strings.
	 * How instanceof is checking runtime objects. instanceof will check the
	 * parameter that we are passing to obj is real time object or not.
	 * 
	 */

	public class Car1 {

		private String vinNumber;
		private String make;
		private String model;

		// Creating the constructor

		public Car1(String vinNumber, String make, String model)

		{
			this.vinNumber = vinNumber;
			this.make = make;
			this.model = model;
		}

		// Here the requirement is "If vinNumbers are equal the cars are equal"
		
		@Override
		public boolean equals(Object obj) {

			// checking the parameter is real time object Car or not.
			// if it is other than real time Car (String ie "Satya") it should
			// return False.
			
			if (obj instanceof Car1)

			{
				Car1 that = (Car1) obj; // Casting
				return this.vinNumber.equals(that.vinNumber);

			} else
			{
				return false;

			}
						
		}//end of equals method
		
		//Overriding the hashCode
		@Override
		
		public int hashCode()
		{
			return vinNumber.hashCode()+make.hashCode()+model.hashCode();
		}
		
		
		
		
		
	}


